home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Utilities / Random / Commodore 64c / SOURCE / offscreenVIC.c < prev    next >
Text File  |  1994-03-20  |  15KB  |  585 lines

  1. /*
  2.     Commodore 64 Emulator v0.1        Earle F. Philhower III 
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is    free software; you can redistribute    it and/or modify
  6.     it under the terms of the GNU General Public License as    published by
  7.     the    Free Software Foundation; either version 2 of the License, or
  8.     (at    your option) any later version.
  9.  
  10.     This program is    distributed    in the hope    that it    will be    useful,
  11.     but    WITHOUT    ANY    WARRANTY; without even the implied warranty    of
  12.     MERCHANTABILITY    or FITNESS FOR A PARTICULAR    PURPOSE.  See the
  13.     GNU    General    Public License for more    details.
  14.  
  15.     You    should have    received a copy    of the GNU General Public License
  16.     along with this    program; if    not, write to the Free Software
  17.     Foundation,    Inc., 675 Mass Ave,    Cambridge, MA 02139, USA.
  18. */
  19. #include "Memory.h"
  20. #include "MemoryCalls.h"
  21. #include "Error.h"
  22. #include "QDOffscreen.h"
  23. #include <GestaltEqu.h>
  24.  
  25. void TotalRedrawVIC(void);
  26. void SetupColorTable(void);
  27. OSErr CreateGDevice (PixMapHandle, GDHandle*);
  28. void NewBitMap (PixMapHandle, Rect*);
  29. OSErr CreateOffScreen (Rect*, short, CTabHandle, CGrafPtr*, GDHandle*);
  30. OSErr SetUpPixMap(short, Rect*, CTabHandle, short, PixMapHandle);
  31. Boolean isPressed (unsigned short);
  32.  
  33. /*
  34.    kPixDepth is the pixel depth of the offscreen pixmap,
  35.    kClutID is the resID of the color table,
  36.    and kDefaultRes has to do with the screen resolution of the GDevice
  37. */
  38.  
  39. #define    kPixDepth    8
  40. #define    kClutID        1001
  41. #define kDefaultRes 0x00480000
  42.  
  43. #define FastDraw(row,col,chr)\
  44. {    tempa=(row<<3) + screenRect.top; tempb=chr<<3;\
  45.     Index2Color (RAM[55296 + chr], &frontCol);\
  46.     RGBForeColor (&frontCol);\
  47.     for (line=0;line<8;line++)\
  48.         for (h=(col<<3)+screenRect.left,pos=0x80;pos>0;pos>>=1,++h)\
  49.             if (*(VICCharDefs+tempb+line)&pos) {\
  50.                 MoveTo(h,line+tempa);\
  51.                 Line(0,0);}\
  52. }
  53.  
  54. /*
  55.                 *(lineStart[tempa+line]+h) = RAM[55296+chr];\
  56.    currently, everything uses FastDraw.  I had FullDraw in there because the cursor
  57.    wasn't flashing when the FastDraw macro was slower than it is now.
  58. */
  59.  
  60. #define FullDraw(row,col,chr)\
  61. {    tempa=(row<<3) + screenRect.top; tempb=chr<<3;\
  62.     Index2Color (RAM[55296 + chr], &frontCol);\
  63.     for (line=0;line<8;line++)\
  64.         for (h=(col<<3) + screenRect.left,pos=0x80;pos>0;pos>>=1,++h)\
  65.             if (*(VICCharDefs+tempb+line)&pos)  {\
  66.                 RGBForeColor (&frontCol);\
  67.                 MoveTo(h,line+tempa);\
  68.                 Line(0,0);}\
  69.             else {\
  70.                 RGBForeColor (&backCol);\
  71.                 MoveTo(h,line+tempa);\
  72.                 Line(0,0);}\
  73. }
  74.  
  75. CWindowPtr VICWind;
  76. byte VICText[1024], VICColor[1024], VICRegister[0x2f];
  77. word VICAddrBase, VICScreenPage, VICCharBase;
  78. byte VICBank, *VICCharDefs;
  79. byte *lineStart[200];
  80.  
  81. Rect fullRect, leftRect, rightRect, topRect, botRect, spr, screenRect;
  82. PixMapHandle spriteMapH;
  83. CTabHandle VICTab;
  84. GDHandle offDev;
  85. RGBColor VICcolors[16];
  86. CGrafPtr offScreenPtr;
  87. CGrafPtr spriteGraf;    /* not used yet */
  88.  
  89.  
  90. int VICInitialize()
  91. {
  92.     int row;
  93.     short err;
  94.     short i;
  95.     CTabHandle vicColors;
  96.  
  97.     SetRect(&fullRect,0,0,336,210);
  98.     SetRect(&screenRect,8,5,328,205);
  99.     SetRect(&leftRect,0,0,8,210);
  100.     SetRect(&rightRect,328,0,336,210);
  101.     SetRect(&topRect,0,0,336,5);
  102.     SetRect(&botRect,0,205,336,210);
  103.     SetRect(&spr,0,0,24,21);
  104.     SetupColorTable();
  105.     VICWind = (CWindowPtr)GetNewCWindow (128, nil, (WindowPtr)-1L);
  106.     if (VICWind==nil) return (kWindowMissing);
  107.     vicColors = VICTab;
  108.     err = HandToHand((Handle*)&vicColors);
  109.     (**(VICWind->portPixMap)).pixelType = 0;
  110.     (**(VICWind->portPixMap)).cmpCount = 1;
  111.     (**(VICWind->portPixMap)).cmpSize = kPixDepth;
  112.     (**(VICWind->portPixMap)).pmTable = vicColors;
  113.     DisposCTable(vicColors);
  114.     ShowWindow((WindowPtr)VICWind);
  115.     SetPort((GrafPtr)VICWind);
  116.     SelectWindow((WindowPtr)VICWind);
  117.     spriteMapH = NewPixMap();
  118.     SetUpPixMap(kPixDepth, &spr, VICTab, kPixDepth*(spr.right-spr.left), spriteMapH);
  119.     CreateOffScreen (&fullRect, kPixDepth, VICTab, &offScreenPtr, &offDev);
  120.     for (row=0; row<200; row++)
  121.         lineStart[row]=(byte*)((**(offScreenPtr->portPixMap)).baseAddr)+((**(offScreenPtr->portPixMap)).rowBytes - 0x8000)*row;
  122.     return(kNoError);
  123. }
  124.  
  125. void VICAddrAdjust()
  126. {
  127.     VICBank=(RAM[0xdd00]&3)^3;
  128.     VICAddrBase=VICBank*16384;
  129.     VICScreenPage=((RAM[0xd018]&0xf0)>>4)*0x0400+VICAddrBase;
  130.     VICCharBase=((RAM[0xd018]&0x0e)*1024);
  131.     if ((VICBank==1)||(VICBank==3))
  132.         VICCharDefs=RAM+(VICAddrBase+VICCharBase);
  133.     else 
  134.         if (VICCharBase==4096) VICCharDefs=charROM;
  135.         else if (VICCharBase==6144) VICCharDefs=charROM+0x0800;
  136.         else VICCharDefs=RAM+(VICAddrBase+VICCharBase);
  137. }
  138.  
  139. byte NotSameVIC()
  140. {
  141.     register byte addr;
  142.     
  143.     for (addr=0; addr<0x2f; addr++) {
  144.         if (addr==0x11)
  145.         {    if ((RAM[0xd011]&127)!=(VICRegister[0x11]&127))
  146.             return 1;}
  147.         else if (addr==0x12);
  148.         else if (RAM[0xd000+addr]!=VICRegister[addr]) return 1; }
  149.     return 0;
  150. }
  151.  
  152. void DrawSprites()
  153. {
  154.     byte spriteNum, row, *spb0, *spb1, *spb2;
  155.     word xpos, ypos, addr0, addr1, addr2;
  156.     Rect t;
  157.     GrafPtr savePort;
  158.     GDHandle gdh;
  159.     
  160. /*    BlockMove((**VICMapH).baseAddr, (**fullMapH).baseAddr,
  161.                 GetPtrSize((**VICMapH).baseAddr));
  162. */
  163.     SetPortPix (spriteMapH);
  164.     for (spriteNum=0; spriteNum<8; spriteNum++)
  165.         if (VICRegister[0x15]&(1<<spriteNum)) {
  166.             xpos=VICRegister[0x00+spriteNum*2]-24;
  167.             ypos=VICRegister[0x01+spriteNum*2]-50;
  168.             xpos += (VICRegister[0x10]&(1<<spriteNum))?256:0;
  169.             t.top=ypos;t.left=xpos;
  170.             t.right=t.left+24+((VICRegister[0x1d]&(1<<spriteNum))?24:0);
  171.             t.bottom=t.top+21+((VICRegister[0x17]&(1<<spriteNum))?21:0);
  172.             addr0 = VICAddrBase+RAM[VICScreenPage+1016+spriteNum]*64;
  173.             addr1 = addr0+1;
  174.             addr2 = addr1+1;
  175.             spb0 = (byte*) ((**spriteMapH).baseAddr);
  176.             spb1 = spb0+1;
  177.             spb2 = spb0+2;
  178.             for (row=0; row<21; row++) {
  179.                 spb0[row<<2]=RAM[addr0+row*3];
  180.                 spb1[row<<2]=RAM[addr1+row*3];
  181.                 spb2[row<<2]=RAM[addr2+row*3]; }
  182.             CopyBits((BitMap*)*spriteMapH,(BitMap*)(*(offScreenPtr->portPixMap)),&spr,&t,srcOr,nil); }
  183.     SetPortPix (offScreenPtr->portPixMap);
  184. }
  185.  
  186. /*
  187. void ScrollScreen()
  188. {
  189.     word xscroll, yscroll;
  190.     
  191.     xscroll=VICRegister[0x16]&7; yscroll=(VICRegister[0x11]&7)-3;
  192.     if (yscroll>0)
  193.         BlockMove(lineStart[0],lineStart[yscroll],(320/8)*(200-yscroll));
  194.     else if (yscroll<0)
  195.         BlockMove(line
  196. */    
  197. void DrawTextScreen(byte total)
  198. {
  199.     word chr;
  200.     byte row, col, line, pos;
  201.     register word tempa, tempb;
  202.     GrafPtr savePort;
  203.     GDHandle saveDev;
  204.     Rect back;
  205.     short h;
  206.     RGBColor backCol, frontCol;
  207.     
  208.     row=col=0;
  209.     GetPort (&savePort);
  210.     saveDev = GetGDevice();
  211.     SetPort ((GrafPtr)offScreenPtr);
  212.     SetGDevice (offDev);
  213.     PenSize(1,1);
  214. /*    SetOrigin(-(VICRegister[0x16]&7),-((VICRegister[0x11]&7)-3));*/
  215.     if (VICRegister[0x11]&32)    /*     High Res mode    */
  216.     {
  217.         VICCharDefs=RAM+VICAddrBase+((VICRegister[0x18]&8)?8192:0);
  218.         for (chr=0;chr<1000;chr++) {
  219.             FastDraw(row,col,chr);
  220.             if (++col>39) {col=0;row++;} }
  221.         }
  222.     else if (total)     {
  223.             Index2Color (VICRegister[0x21], &backCol);
  224.             RGBBackColor (&backCol);
  225.             EraseRect (&screenRect);
  226.             for (chr=0;chr<1000;chr++) {
  227.                 FastDraw(row,col,RAM[chr+VICScreenPage]);
  228.                 VICText[chr]=RAM[chr+VICScreenPage];
  229.                 if (++col>39) {col=0;row++;} } }
  230.     else  {
  231.             Index2Color (VICRegister[0x21], &backCol);
  232.             RGBBackColor (&backCol);
  233.             for (chr=0;chr<1000;chr++) {
  234.                 if (VICText[chr]!=RAM[chr+VICScreenPage]) {
  235.                     SetRect (&back, (col<<3)+screenRect.left, (row<<3)+screenRect.top,
  236.                                     (col<<3)+screenRect.left+8, (row<<3)+screenRect.top+8);
  237.                     EraseRect (&back);
  238.                     FastDraw(row,col,RAM[chr+VICScreenPage]);
  239.                     VICText[chr]=RAM[chr+VICScreenPage]; }
  240.                 if (++col>39) {col=0;row++;} } }
  241. /*    SetOrigin(0,0);*/
  242.     SetPort (savePort);
  243.     SetGDevice (saveDev);
  244. /*    ScrollRect(&fullRect, VICRegister[0x16]&7,(VICRegister[0x11]&7)-3,nil);*/
  245. }
  246.  
  247. void DrawBorders()
  248. {
  249.     GrafPtr savePort;
  250.     GDHandle saveDev;
  251.     RGBColor borderCol;
  252.     Rect newLeft, newRight, newTop, newBottom;
  253.  
  254.     GetPort (&savePort);
  255.     saveDev = GetGDevice();
  256.     SetPort ((GrafPtr)offScreenPtr);
  257.     SetGDevice (offDev);
  258.     Index2Color (VICRegister[0x20], &borderCol);
  259.     RGBBackColor (&borderCol);
  260.     if (VICRegister[0x16]&8) {
  261.         EraseRect(&leftRect);
  262.         EraseRect(&rightRect);
  263.     }
  264.     else {
  265.         newLeft = leftRect;
  266.         OffsetRect (&newLeft, 4, 0);
  267.         InsetRect (&newLeft, -4, 0);
  268.         newRight = rightRect;
  269.         OffsetRect (&newRight, -4, 0);
  270.         InsetRect (&newRight, -4, 0);
  271.         EraseRect(&newLeft);
  272.         EraseRect(&newRight);
  273.     }
  274.     if (VICRegister[0x11]&8) {
  275.         EraseRect(&botRect);
  276.         EraseRect(&topRect);
  277.     }
  278.     else {
  279.         newBottom = botRect;
  280.         OffsetRect (&newBottom, 0, -2);
  281.         InsetRect (&newBottom, 0, -2);
  282.         newTop = topRect;
  283.         OffsetRect (&newTop, 0, 2);
  284.         InsetRect (&newTop, 0, -2);
  285.         EraseRect(&newBottom);
  286.         EraseRect(&newTop);
  287.     }
  288.     SetPort (savePort);
  289.     SetGDevice (saveDev);
  290. }
  291.  
  292. void CopyPortToScreen()
  293. {
  294.     ForeColor (blackColor);
  295.     BackColor (whiteColor);
  296.     CopyBits ((BitMapPtr)*(offScreenPtr->portPixMap), &((GrafPtr)VICWind)->portBits, &fullRect, &fullRect, srcCopy, nil);
  297. }
  298.  
  299. void BlankScreen()
  300. {
  301.     GrafPtr savePort;
  302.     GDHandle saveDev;
  303.     RGBColor backCol;
  304.  
  305.     GetPort (&savePort);
  306.     saveDev = GetGDevice();
  307.     SetPort ((GrafPtr)offScreenPtr);
  308.     SetGDevice (offDev);
  309.     Index2Color (VICRegister[0x21], &backCol);
  310.     RGBBackColor (&backCol);
  311.     EraseRect (&fullRect);
  312.     SetPort (savePort);
  313.     SetGDevice (saveDev);
  314.     CopyPortToScreen();
  315.     return;
  316. }
  317.  
  318. void RedrawVIC()
  319. {
  320.     if (NotSameVIC()) { TotalRedrawVIC(); return; }
  321.     VICAddrAdjust();
  322.     SetPort((GrafPtr)VICWind);
  323.     if (!VICRegister[0x11]&16) {
  324.         BlankScreen(); 
  325.         return;}
  326.     DrawTextScreen(0);
  327.     DrawBorders();
  328.     if (VICRegister[0x15])
  329.         DrawSprites();
  330.     CopyPortToScreen();
  331. }
  332.  
  333. void TotalRedrawVIC()
  334. {
  335.     register byte addr;
  336.  
  337.     for (addr=0; addr<0x2f; addr++)
  338.         VICRegister[addr]=RAM[0xd000+addr];
  339.     VICAddrAdjust();
  340.     SetPort((GrafPtr)VICWind);    
  341.     if (VICRegister[0x11]&16)            /* screen blanking */
  342.         ;
  343.     else 
  344.     {
  345.         BlankScreen();
  346.         return;
  347.     }
  348.     DrawBorders();
  349.     DrawTextScreen(1);
  350.     if (VICRegister[0x15])
  351.         DrawSprites();
  352.     CopyPortToScreen();
  353. }
  354.  
  355. void SetupColorTable (void)
  356. {
  357.     VICTab = GetCTable (kClutID);
  358.     HNoPurge ((Handle)VICTab);
  359.     MoveHHi ((Handle)VICTab);
  360. }
  361.  
  362. /*
  363.    These next three are almost verbatim from the Tech Note "Principia Off Screen"
  364. */
  365.  
  366. OSErr CreateGDevice (PixMapHandle basePixMap, GDHandle *retGDevice)
  367. {
  368.     GDHandle   newDevice;
  369.     ITabHandle embryoITab;
  370.     Rect       deviceRect;
  371.     OSErr       error;
  372.  
  373.     error =    noErr;
  374.     newDevice =    nil;
  375.     embryoITab = nil;
  376.  
  377.     newDevice = (GDHandle)NewHandle(sizeof(GDevice));
  378.     if (newDevice != nil)
  379.     {
  380.         embryoITab = (ITabHandle)NewHandleClear(2);
  381.         if (embryoITab != nil)
  382.         {
  383.             deviceRect = (**basePixMap).bounds;
  384.             (**newDevice).gdRefNum = 0;
  385.             (**newDevice).gdID = 0;
  386.             if ((**basePixMap).pixelSize <=    8)
  387.                 (**newDevice).gdType = clutType;
  388.             else
  389.                 (**newDevice).gdType = directType;
  390.             (**newDevice).gdITable = embryoITab;
  391.             (**newDevice).gdResPref    = 4;
  392.             (**newDevice).gdSearchProc = nil;
  393.             (**newDevice).gdCompProc = nil;
  394.             (**newDevice).gdFlags =    0;
  395.             (**newDevice).gdPMap = basePixMap;
  396.             (**newDevice).gdRefCon = 0;
  397.             (**newDevice).gdNextGD = nil;
  398.             (**newDevice).gdRect = deviceRect;
  399.             (**newDevice).gdMode = -1;
  400.             (**newDevice).gdCCBytes    = 0;
  401.             (**newDevice).gdCCDepth    = 0;
  402.             (**newDevice).gdCCXData    = 0;
  403.             (**newDevice).gdCCXMask    = 0;
  404.             (**newDevice).gdReserved = 0;
  405.             if ((**basePixMap).pixelSize > 1)
  406.                 SetDeviceAttribute(    newDevice, gdDevType, true );
  407.             SetDeviceAttribute(    newDevice, noDriver, true );
  408.             if ((**basePixMap).pixelSize <=    8)
  409.             {
  410.                 MakeITable((**basePixMap).pmTable, (**newDevice).gdITable,(**newDevice).gdResPref);
  411.                 error =    QDError();
  412.             }
  413.         }
  414.         else
  415.             error =    MemError();
  416.     }
  417.     else
  418.         error =    MemError();
  419.     if (error != noErr)
  420.     {
  421.         if (embryoITab != nil)
  422.             DisposHandle( (Handle)embryoITab );
  423.         if (newDevice != nil)
  424.             DisposHandle( (Handle)newDevice    );
  425.     }
  426.     else
  427.         *retGDevice    = newDevice;
  428.     return error;
  429. }
  430.  
  431. OSErr CreateOffScreen (Rect *bounds, short depth, CTabHandle colors, CGrafPtr *retPort,    GDHandle *retGDevice)
  432. {
  433.     CGrafPtr    newPort;
  434.     PixMapHandle    newPixMap;
  435.     GDHandle    newDevice;
  436.     long        qdVersion;
  437.     GrafPtr        savedPort;
  438.     SignedByte    savedState;
  439.     short        bytesPerRow;
  440.     OSErr        error;
  441.  
  442.     newPort    = nil;
  443.     newPixMap = nil;
  444.     newDevice = nil;
  445.     error =    noErr;
  446.     if (colors != nil)
  447.     {
  448.         savedState = HGetState(    (Handle)colors );
  449.         HNoPurge( (Handle)colors );
  450.     }
  451.     bytesPerRow    = ((depth *    (bounds->right - bounds->left) + 31) >>    5) << 2;
  452.     (void)Gestalt( gestaltQuickdrawVersion,    &qdVersion );
  453.     if (depth == 1 || depth    == 2 ||    depth == 4 || depth    == 8 ||
  454.             ((depth    == 16 || depth == 32) && qdVersion >= gestalt32BitQD))
  455.     {
  456.         if (bytesPerRow    <= 0x3FFE)
  457.         {
  458.             if (depth <= 8)
  459.                 if (colors == nil)
  460.                   error    = paramErr;    /* no table for indexed depth */
  461.         }
  462.         else
  463.             error =    paramErr; /* too many bytes */
  464.     }
  465.     else
  466.         error =    paramErr; /* invalid depth */
  467.     if (error == noErr)
  468.     {
  469.         newPort    = (CGrafPtr)NewPtr(    sizeof (CGrafPort) );
  470.         if (newPort    != nil)
  471.         {
  472.             GetPort    (&savedPort);
  473.             OpenCPort (newPort);
  474.             newPort->portRect =    *bounds;
  475.             RectRgn    (newPort->visRgn, bounds);
  476.             ClipRect (bounds);
  477.             error =    SetUpPixMap    (depth,    bounds,    colors,    bytesPerRow, newPort->portPixMap);
  478.             if (error == noErr)
  479.             {
  480.                 newPixMap =    newPort->portPixMap;
  481.                 error =    CreateGDevice( newPixMap, &newDevice );
  482.             }
  483.             SetPort( savedPort );
  484.         }
  485.         else
  486.             error =    MemError();
  487.     }
  488.     if (colors != nil)
  489.         HSetState( (Handle)colors, savedState );
  490.     if (error != noErr)
  491.     {
  492.         if (newPixMap != nil)
  493.         {
  494.             DisposCTable( (**newPixMap).pmTable    );
  495.             DisposPtr( (**newPixMap).baseAddr );
  496.         }
  497.         if (newDevice != nil)
  498.         {
  499.             DisposHandle( (Handle)(**newDevice).gdITable );
  500.             DisposHandle( (Handle)newDevice    );
  501.         }
  502.         if (newPort    != nil)
  503.         {
  504.             CloseCPort(    newPort    );
  505.             DisposPtr( (Ptr)newPort    );
  506.         }
  507.     }
  508.     else
  509.     {
  510.         *retPort = newPort;
  511.         *retGDevice    = newDevice;
  512.     }
  513.     return error;
  514. }
  515.  
  516. OSErr SetUpPixMap(short    depth, Rect    *bounds, CTabHandle    colors,    short bytesPerRow, PixMapHandle    aPixMap)
  517. {
  518.     CTabHandle newColors;
  519.     Ptr           offBaseAddr;
  520.     OSErr       error;
  521.  
  522.     error =    noErr;
  523.     newColors =    nil;
  524.     offBaseAddr    = nil;
  525.     if (depth <= 8)
  526.     {
  527.         newColors =    colors;
  528.         error =    HandToHand(    (Handle    *)&newColors );
  529.     }
  530.     else
  531.     {
  532.         newColors =    (CTabHandle)NewHandle(sizeof(ColorTable) - sizeof(CSpecArray));
  533.         error =    MemError();
  534.     }
  535.     if (error == noErr)
  536.     {
  537.         offBaseAddr    = NewPtr((unsigned long)bytesPerRow    * (bounds->bottom -    bounds->top) );
  538.         if (offBaseAddr    != nil)
  539.         {
  540.             (**aPixMap).baseAddr = offBaseAddr;
  541.             (**aPixMap).rowBytes = bytesPerRow | 0x8000;
  542.             (**aPixMap).bounds = *bounds;
  543.             (**aPixMap).pmVersion =    0;
  544.             (**aPixMap).packType = 0;
  545.             (**aPixMap).packSize = 0;
  546.             (**aPixMap).hRes = kDefaultRes;
  547.             (**aPixMap).vRes = kDefaultRes;
  548.             (**aPixMap).pixelSize =    depth;
  549.             (**aPixMap).planeBytes = 0;
  550.             (**aPixMap).pmReserved = 0;
  551.             if (depth <= 8)      /* PixMap    is indexed */
  552.             {
  553.                 (**aPixMap).pixelType =    0;
  554.                 (**aPixMap).cmpCount = 1;
  555.                 (**aPixMap).cmpSize    = depth;
  556.                 (**aPixMap).pmTable    = newColors;
  557.             }
  558.             else
  559.             {
  560.                 (**aPixMap).pixelType =    RGBDirect;
  561.                 (**aPixMap).cmpCount = 3;
  562.                 if (depth == 16)
  563.                     (**aPixMap).cmpSize    = 5;
  564.                 else
  565.                     (**aPixMap).cmpSize    = 8;
  566.                 (**newColors).ctSeed = 3 * (**aPixMap).cmpSize;
  567.                 (**newColors).ctFlags =    0;
  568.                 (**newColors).ctSize = 0;
  569.                 (**aPixMap).pmTable    = newColors;
  570.             }
  571.         }
  572.         else
  573.             error =    MemError();
  574.     }
  575.     else
  576.         newColors =    nil;
  577.     if (error != noErr)
  578.     {
  579.         if (newColors != nil)
  580.             DisposCTable(newColors);
  581.     }
  582.     return error;
  583. }
  584.  
  585.